<template>
  <div class="goodsListItem" @click="goodsItemClick">
    <img :src="goodsItem.show.img" @load="imgLoad" alt="">
    <div class="itemContent">
      <p class="itemTitle">{{ goodsItem.title }}</p>
      <span class="price">￥{{ goodsItem.price }}</span>
      <span class="collect">{{ goodsItem.cfav }}</span>
    </div>
  </div>
</template>

<script>
export default {
  name: "GoodsListItem",
  data() {
    return {}
  },
  props: {
    goodsItem: {
      type: Object,
      default() {
        return {}
      }
    }
  },
  mounted() {

  },
  methods: {
    imgLoad() {
      // 使用事件总线$bus广播图片加载完成事件
      this.$bus.$emit('itemImgLoad')
    },
    goodsItemClick() {
      console.log('商品详情页');
      this.$router.push('/detail/' + this.goodsItem.iid)
    }
  }
}
</script>

<style scoped>
.goodsListItem {
  padding-bottom: 40px;
  position: relative;
  width: 49%;
}

.goodsListItem img {
  width: 100%;
  border-radius: 5px;
}

.goodsListItem .itemContent {
  position: absolute;
  bottom: 5px;
  left: 0;
  right: 0;
  overflow: hidden;
  text-align: center;
  font-size: 14px;
}

.goodsListItem .itemTitle {
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
  margin-bottom: 3px;
}

.goodsListItem .price {
  color: var(--color-high-text);
  margin-right: 20px;
}

.goodsListItem .collect {
  position: relative;
}

.goodsListItem .collect:before {
  position: absolute;
  content: '';
  width: 15px;
  height: 15px;
  left: -15px;
  top: 0px;
  background: url("~assets/img/common/collect.svg") 0 0/15px 15px;
}
</style>
